package com.example.service.impl;

import com.example.entity.ExamQuestionBank;
import com.example.entity.ExamQuestionPack;
import com.example.mapper.ExamQuestionBankMapper;
import com.example.mapper.ExamQuestionPackMapper;
import com.example.service.ExamQuestionBankService;
import com.example.service.ExamQuestionPackService;
import com.example.vo.ExamPaperPackageDetailVO;
import com.example.vo.ExamPaperPackageSummaryVO;
import com.example.vo.ExamQuestionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class ExamQuestionPackServiceImpl implements ExamQuestionPackService {

    @Autowired
    private  ExamQuestionPackMapper examQuestionPackMapper;

    @Autowired
    private ExamQuestionBankMapper examQuestionBankMapper;

    public ExamQuestionPackServiceImpl(ExamQuestionPackMapper examQuestionPackMapper) {
        this.examQuestionPackMapper = examQuestionPackMapper;
    }

    // 查询所有的  试题包基本数据与题目数量
    @Override
    public List<ExamPaperPackageSummaryVO> getAllExamPaperPackagesSummary(){
        return examQuestionPackMapper.getExamPaperPackageSummary();
    }

    // 根据选题包名字获取详细信息
    @Override
    public ExamPaperPackageDetailVO getExamPaperPackageDetail(String packageName){
        List<ExamQuestionPack> examQuestionPacks = examQuestionPackMapper.selectByPackageName(packageName);
        log.info("examQuestionPacks{}", examQuestionPacks);
        ExamPaperPackageDetailVO detailVO = new ExamPaperPackageDetailVO();
        detailVO.setBusiType1(examQuestionPacks.get(0).getBusiType1());
        detailVO.setBusiTypeId1(examQuestionPacks.get(0).getBusiTypeId1());
        detailVO.setBusiTypeId2(examQuestionPacks.get(0).getBusiTypeId2());
        detailVO.setBusiTypeId3(examQuestionPacks.get(0).getBusiTypeId3());
        detailVO.setBusiTypeName1(examQuestionPacks.get(0).getBusiTypeName1());
        detailVO.setPackName(examQuestionPacks.get(0).getPackName());
        detailVO.setVersion(examQuestionPacks.get(0).getVersion());
        detailVO.setBusiTypeName2(examQuestionPacks.get(0).getBusiTypeName2());
        detailVO.setBusiTypeName3(examQuestionPacks.get(0).getBusiTypeName3());


        ArrayList<ExamPaperPackageDetailVO.Question> questionList = new ArrayList<>();
        examQuestionPacks.forEach(examQuestionPack -> {

            Integer qsId = examQuestionPack.getQsId();
            log.info("qsId{}", qsId);

            ExamQuestionBank questionBank = examQuestionBankMapper.selectById(qsId);
            ExamPaperPackageDetailVO.Question question = new ExamPaperPackageDetailVO.Question();
            question.setBusiTypeId1(questionBank.getBusiType1());
            question.setId(qsId);
            question.setVersion(questionBank.getVersion());
            question.setAnalysis(questionBank.getAnalysis());
            question.setQuestionType(questionBank.getQuestionType());
            question.setCorrectAnsJson(questionBank.getCorrectAnsJson());
            question.setQsContent(questionBank.getQsContent());
            question.setCorrectAnsJson(questionBank.getCorrectAnsJson());
            question.setQsCorrectAns(questionBank.getQsCorrectAns());
            question.setLevel(String.valueOf(questionBank.getLevel()));
            question.setBusiTypeName1(questionBank.getBusiTypeName1());
            question.setBusiTypeName2(questionBank.getBusiTypeName2());
            question.setBusiTypeName3(questionBank.getBusiTypeName3());
            question.setBusiTypeId1(String.valueOf(questionBank.getBusiTypeId1()));
            question.setBusiTypeId2(String.valueOf(questionBank.getBusiTypeId2()));
            question.setBusiTypeId3(String.valueOf(questionBank.getBusiTypeId3()));
            question.setBusiType1(questionBank.getBusiType1());
            question.setBusiTypeId1(questionBank.getBusiType1());
            question.setKeyword(questionBank.getKeyword());

            questionList.add(question);


        });

        detailVO.setQuestions(questionList);




        return detailVO;
    }


}
